<!DOCTYPE html>
<html>
<head>
	<div th:include="base-libs :: base-libs" />
	<script th:src="@{/service/js/jtqy.js}"></script>
<head/>
	<title>转介审核</title>
	<style type="text/css">
		.spanBtn{
			font-weight: bold;
			color: blue;
			cursor:pointer;
		}
	</style>
	<script th:inline="javascript">
        /**读取request中的初始化数据*/
        var tdxxAry = [[${tdxxAry}]];
	</script>
	<script type="text/javascript">
		var selection;
		$(function() {
		 	initView();
            $("#btnQuery").trigger("click");
		});
		
		function queryForm() {
			$("#zjshTable").datagrid({url: contextRoot+"jtqy/queryZjsqByPage.service"});
		}
		
		function toDetail(row){
			//var selection = $("#dgForm").datagrid("getChecked");
			StoreCache.setCache("JTQYXQINFO", row);
			location = "detail.html?to=zjshDetail&JMXXID=" + row.JMXXID;
		}
		
		function initView(){
            $("#XQYTD").createOptions(tdxxAry,{valueField : "TDID" , textField : "TDMC"});
			//回车查询
			enterToQuery(queryForm);
			
			$('#zjshTable').datagrid({
					idField : "ZJSQID",
					striped : true,
					clickToSelect: true,
					fit:true,
					fitColumns: true,
					scrollbarSize:0,
					pagination : true,
					pageList: [10, 25, 50, 100, 200],
					scrollBarSize:0,
					border: false,
					rownumbers:true,
					columns:[[
//							{field:'xz',checkbox: true},
			   				{field:'XM', title:'姓名', width: 60, align: 'center'},
							{field:'ZJHM', title:'证件号码', width: 125, align: 'center',formatter: function(value,row){
								return formatIdcard(value);
							}},
							{field:'SJHM', title:'手机号码', width: 100, align: 'center'},
							{field:'JTZZ', title:'家庭住址', width: 160, align: 'center',formatter: function(value,row){
								return formatTitle(value);
							}},
							{field:'QYSJ', title:'签约时间', width: 130, align: 'center', formatter:function(value){
								/*if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}*/
								return value;
							}},
							{field:'QYTDMC', title:'原签约团队', width: 90, align: 'center',formatter: function(value,row){
								return formatTitle(value);
							}},
							{field:'FWBMC', title:'签约服务包', width: 100, align: 'center',formatter: function(value,row){
								return formatTitle(value);
							}},
							{field:'SQRQ', title:'申请时间', width: 75, align: 'center', formatter:function(value){
								if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}
							}},
							{field:'ZJYYMS', title:'转介原因', width: 100, align: 'center',formatter: function(value,row){
								return formatTitle(value);
							}},
							{field:'XQYTDMC', title:'转入团队', width: 100, align: 'center'},
							{field:'cz', title:'操作', width: 100, align: 'center',formatter:function(value,row){
								row = JSON.stringify(row).replace(/"/g, '&quot;'); 
                                return '<span class="spanBtn" onclick="toDetail(' + row + ')">审核</span>';
							}}
					]],
					onBeforeLoad: function(params){
						var options = $(this).datagrid("options");
						if(!StringUtils.isEmpty(options.url)){
							getContainerDataByClassName('zjshCondition','condition',params);//查询条件
							formatTdid(params,'XQYTD');
						}
					},
			})

        }

        /** 团队为空时，查询所有团队  */
        function formatTdid(params,field){
            if(StringUtils.isEmpty(params[field])){
                var tdidArr = [];
                $("#XQYTD option").each(function(){
                    var value = $(this).val();
                    if(!StringUtils.isEmpty(value)){
                        tdidArr.push(value);
                    }
                })
                params[field] = tdidArr.join(',');
            }
        }

		/** 审核转介申请  */
		function checkZjxx(){
			var selections = $("#zjshTable").datagrid('getSelections');
			if(selections.length>0){
				var first = selections[0];
				var yqytd = first.YQYTD,
					zjyy = first.ZJYYMS;
				
				var isContinue = true;
				$.each(selections, function(i,item){
					if(item.YQYTD != yqytd || item.ZJYYMS != zjyy){
						isContinue = false;
						$.QuickAlert.alertFail({content : "您选中的居民，转入团队/转介原因不一致，无法一起审核。请勾选签约团队相同/转介原因相同的居民进行批量审核！"});
					}
				})
				
				if(isContinue){
					var info = "您选中了<span style='color:red'>"+ selections.length +"</span>条记录，"
								+"均由<span style='color:red'>"+first.YQYTDMC+"</span>转入，转介原因为"
					            +"<span style='color:red'>"+ zjyy + "</span>，是否确认接受转介？";
					            
		            var lay = parent.layer.confirm(info, {
	            	    btn: ['接受','拒绝'],
		            	btn1: function(index,layero){
			            	  var params = {"SHZT":"1",zjryArr:JSON.stringify(selections)};
			            	  $.QuickRemote.AjaxJson(contextRoot + "jtqy/checkZjsq", checkZjxxBack, params);
			            	  parent.layer.close(index);
			            },
			            btn2: function(){
			            	 var params = {"SHZT":"2",zjryArr:JSON.stringify(selections)};
			            	 $.QuickRemote.AjaxJson(contextRoot + "jtqy/checkZjsq", checkZjxxBack, params);
			            },
		            });
					            
				}
			}else{
				$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
			}
		}
		
		/** 转介审核回调  */
		function checkZjxxBack(result){
			
			if(result.state)
			{
				$.QuickAlert.alertNormal(result.info.success, {callback: function(){
					$.QuickUrlUtils.redirectUrl("indexZjsh.html");
				}});
			}
			else
			{
				var info = result["info"];
				$.QuickAlert.alertFail({content: info["faultInfo"]});
			}
			
		}
		
		/** 导出 */
	   	function download(){
	   	    var params = {"XQYTD":$("#XQYTD").val()};
            formatTdid(params,"XQYTD");
            $("#XQYTD_down").val(params.XQYTD);//导出条件XQYTD
	   		$("#downloadForm").submit();
	   	}
	</script>
	</head>
<body>
<div class="easyui-layout" fit="true">
	<div region="north" border="false" style="overflow:hidden;border:0;background:#f9f9f9">
		<div style="width: 100%; margin-left: 30px">
			<h3 style="line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;text-align:center">转介审核列表</h3>
		</div>
		<form action="downloadZjsh.service" method="post" enctype="multipart/form-data" id="downloadForm">
			<table class="form-table" id="zjshCondition">
				<tr>
					<td class="td-text">姓名：</td>
					<td class="td-content">
						<input type="hidden" name="SHZT" value="0"  class="condition"/>
						<input name="XM" class="form-control condition"  style="width: 100%;">
					</td>
					<td class="td-text">证件号码：</td>
					<td class="td-content">
						<div style="display: inline;">
							<input name="ZJHM" class="form-control condition" style="width: 100%;" />
						</div>
					</td>
					<td class="td-text">转入团队：</td>
					<td class="td-content">
						<input id="XQYTD_down" name="XQYTD_down" type="hidden"/>
						<select id="XQYTD" name="XQYTD" class="form-control condition" style="width: 100%;">
							<option value="">请选择</option>
						</select>
					</td>
					<td class="td-text" style="text-align:center;width:150px;">
						<button class="btn btn-info" type="button" onclick="queryForm()" id="btnQuery">查询</button>
						<button class="btn btn-info" type="button" onclick="download()">导出</button>
					</td>
				</tr>
			</table>
		</form>
		<div style="margin-top:10px;padding-left:30px;padding-bottom:10px;">
			<!--无法批量修改协议，该功能暂时去除--多选框去除同时添加上行号 -->
			<!--<button class="btn btn-info" type="button" onclick="checkZjxx()">审核</button>-->
		</div>
	</div>
	<div region="center" border="false">
		<table id="zjshTable"></table>
	</div>
	
</div>
</body>
</html>



